package com.ynding.spring.idea.ddd.biz.shared.lottery;

import com.ynding.spring.idea.ddd.common.aax.util.LotteryContext;
import com.ynding.spring.idea.ddd.common.service.facade.lottery.request.RiskReq;
import com.ynding.spring.idea.ddd.common.service.facade.lottery.result.IssueResult;
import com.ynding.spring.idea.ddd.common.service.facade.lottery.result.LotteryConditionResult;
import com.ynding.spring.idea.ddd.common.service.facade.lottery.result.RiskAccessToken;
import com.ynding.spring.idea.ddd.core.service.lottery.service.LotteryConditionService;
import com.ynding.spring.idea.ddd.core.service.lottery.service.LotteryRiskService;
import com.ynding.spring.idea.ddd.core.service.lottery.service.LotteryService;
import org.springframework.stereotype.Component;

/**
 * @author ynding
 * @version 2022/9/11
 **/
@Component
public class LotteryManage {

    private LotteryService lotteryService;
    private LotteryRiskService lotteryRiskService;
    private LotteryConditionService lotteryConditionService;

    public IssueResult issueLottery(LotteryContext lotteryContext) {
        // 权限控制 TODO

        //校验风控
        RiskAccessToken riskToken = lotteryRiskService.accquire(buildRiskReq(lotteryContext));
        // ...
        //活动准入检查
        LotteryConditionResult conditionResult = lotteryConditionService.checkLotteryCondition(lotteryContext.getLotteryId(),lotteryContext.getUserId());
        // ...
        //抽奖并返回结果
        IssueResult issueResponse = lotteryService.issueLottery(lotteryContext);
        return issueResponse;
    }

    private RiskReq buildRiskReq(LotteryContext lotteryContext) {
        return new RiskReq();
    }
}
